package nix.bs.domain;

import java.math.BigDecimal;

public class CartItem {

	private Book book;
	private int count;

	@Override
	public String toString() {
		return "CartItem [book=" + book + ", count=" + count + "]";
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	/**
	 * 小计（使用BigDecimal避免二进制运算误差问题，使用字符串的构造函数）
	 */
	public double getSubTotal() {
		BigDecimal d1 = new BigDecimal(this.book.getPrice() + "");
		BigDecimal d2 = new BigDecimal(this.count + "");
		return d1.multiply(d2).doubleValue();
	}
}
